//
//  UIBarButtonItem+Extensions.swift
//  SwiftDemo
//
//  Created by Chris on 2017/6/16.
//  Copyright © 2017年 chris. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    /// 创建按钮 UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: 文字
    ///   - fontSize: 字体大小
    ///   - target: target
    ///   - action: action
    convenience init(title: String, fontSize: CGFloat = 16, target: Any?, action: Selector, isBack: Bool = false) {
        let btn = UIButton.cj_init(title, fontSize: fontSize, normalColor: .darkGray, highlightedColor: .orange)
        
        if isBack {
            let imagName = "navigationbar_back_withtext"
            
            btn.setImage(UIImage(named:imagName), for: .normal)
            btn.setImage(UIImage(named:imagName + "_highlighted"), for: .highlighted)
            btn.sizeToFit()
        }
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        self.init(customView: btn)
    }
}
